local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerComponent(),script.Parent.Name);
local LikeGame_Cfg=ServerOHOH.config.LikeGame;
local Reward=LikeGame_Cfg.Reward;

local ItemTool=_G.CommonOHOH.load.ItemTool();
function M.new(self,...)
	return M(self,...);
end;
function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.dataBase=self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent());
    self.data = self.dataBase:GetData("likeGame");
end;
function M.RewardCheck(self,receiveIndex)
    local isReceive=true;
    local data=self.data;
    --验证
    if data.receiveCount~=receiveIndex then
        isReceive=false;
    end
    local targetIndex=receiveIndex+1;

    local targetReward=Reward[targetIndex];
    if targetReward.like_count>LikeGame_Cfg.LikeGameCount then
        isReceive=false;
    end  
    if(isReceive)then
        receiveIndex= receiveIndex+1;
        self.ItemCtrl=self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl());
        local key,count= ItemTool.GetRewardByLevel(targetReward.item_id,targetReward.count,self.dataBase:GetData("base").level);
	    self.ItemCtrl:AddAnyThing(key,count,false,false);
        
        self.dataBase:GetData("likeGame").receiveCount=receiveIndex;
        self.dataBase:Execut(function()
        end);
        self.parent:SynchDataToClient("base","likeGame");
    end
    return isReceive;

end;
function M.dtor(self)
	M.super.dtor(self);
end;
local function_list = ServerOHOH.function_list;

M:RegistFunction(function_list.receive_reward,M.RewardCheck)

return M;